package com.dduggs.note.arithmetic.sort;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * Created by CJS on 2016/12/14.
 */
public class SortTest {

    public static void main(String[] args) {

        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        List<SortClass> list = new ArrayList<>();
        String d1 = "2011-5-31 14:40:51";
        String d2 = "2011-5-31 14:40:52";
        String d3 = "2011-5-31 14:40:53";
        String d4 = "2011-5-31 14:40:54";
        Date date1 = null, date2 = null, date3 = null, date4 = null;
        try {
            date1 = format.parse(d1);
            date2 = format.parse(d2);
            date3 = format.parse(d3);
            date4 = format.parse(d4);
        } catch (ParseException e) {
            e.printStackTrace();
        }


        SortClass s1 = new SortClass(1, "10", date4);
        SortClass s2 = new SortClass(2, "40", date3);
        SortClass s3 = new SortClass(3, "30", date2);
        SortClass s4 = new SortClass(4, "20", date1);

        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);

        Collections.sort(list, (m1, m2) -> {
            int a = Integer.parseInt(m1.getStatus());
            int b = Integer.parseInt(m2.getStatus());
            if(a==20&&b!=20){
                return -1;
            }else if(a!=20&&b==20){
                return 1;
            }else{
               return 1;
            }
        });

       /* Collections.sort(list, (m1, m2) -> {
            int a = Integer.parseInt(m1.getStatus());
            int b = Integer.parseInt(m2.getStatus());
            if(a==20&&b!=20){
                return -1;
            }else if(a!=20&&b==20){
                return 1;
            }else{
                Date t1 =  m1.getDate();
                Date t2 =  m2.getDate();
                return t2.compareTo(t1);
            }
        });*/
        for (SortClass s:list) {
            System.out.println(s.getId()+"----"+s.getStatus()+"----"+s.getDate().toString());
        }
    }
}
